package com.zegome.game.gomestory.main.helper;

import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;

public class BackListener {

	public Actor actor;
	public boolean isRemoveAble;
	public ChangeListener backLis1;
	
	public BackListener(Actor actor, ImageButton yes, ImageButton no, final ChangeListener yesLis, final ChangeListener noLis, final ChangeListener backLis){	

		this.actor = actor;
		
		ChangeListener noLis1 = new ChangeListener() {			
			@Override
			public void changed (ChangeEvent event, Actor actor) {
				// TODO Auto-generated method stub
				if(noLis!=null)
					noLis.changed(event, actor);
				isRemoveAble = true;
			}
		};
		
		ChangeListener yesLis1 = new ChangeListener() {			
			@Override
			public void changed (ChangeEvent event, Actor actor) {
				// TODO Auto-generated method stub
				if(yesLis!=null)
					yesLis.changed(event, actor);
				isRemoveAble = true;
			}
		};
		
		ChangeListener backLis1 = new ChangeListener() {			
			@Override
			public void changed (ChangeEvent event, Actor actor) {
				// TODO Auto-generated method stub
				if(backLis!=null)
					backLis.changed(event, actor);
				isRemoveAble = true;		
			}
		};
		
		if(yes!=null)
			yes.addListener(yesLis1);
		if(no!=null)
			no.addListener(noLis1);
		
		if(backLis!=null)
			this.backLis1 = backLis1;
		else
			this.backLis1 = noLis1;
	}
	
	public void checkBack(){	
		if(actor!=null){
			actor.remove();
			actor = null;
		}
		backLis1.changed(null, null);
	}	
}
